layui.extend({
    dtree: 'layui_ext/dist/dtree'
}).use(['jquery', 'layer', 'form', 'table', 'dtree'], function () {
    var $ = layui.jquery;
    var layer = layui.layer;
    var form = layui.form;
    var table = layui.table;

    //保存


    form.on("submit(doSubmit)", function (obj) {
        layer.confirm('确定修改吗', function (index) {
            //序列化表单数据
            var params = $("#dataFrm").serialize();

            $.post("/user/editLogin", params, function (obj) {
                if(obj > 0){
                    layer.msg("修改成功！");
                }else{
                    layer.msg("修改失败！");
                }

                setTimeout(function () {
                    location.reload();
                }, 1000)
            })
        });

    })


    var op;
    $("#pwd").click(function () {
        op = layer.open({
            type: 1,
            title: "修改密码",
            area: ['500px', '300px'],
            content: $("#saveOrUpdateDiv") //这里content是一个普通的String
        });
    });
    //关闭窗口
    $("#guanbi").click(function () {
        layer.close(op)
    })
    $("#qwe").click(function () {
        var loginname = $("#loginname").val();
        var pwd = $("#jpwd").val();
        var pwd1 = $("#pwd1").val();
        var pwd2 = $("#pwd2").val();
        if (pwd == "" || loginname == "" || pwd1 == "") {
            layer.msg("不能为空")
            return false;
        } else if (pwd1 != pwd2) {
            layer.msg("密码不一致")
            return false;
        }
        $.post("/user/editPwd", {loginname: loginname, pwd: pwd, pwd1: pwd1}, function (obj) {
            if (obj == 1) {
                setTimeout(function () {
                    window.parent.location.href = "../sel/toLogin";//#设定跳转的链接地址
                }, 3000)

                layer.msg("修改成功", {
                    time: 3000 //取消自动关闭
                });  // 显示倒计时

                //layer.close(op);
                return false;
            } else {
                layer.msg("旧密码错误");
                return false;
            }
        })
    })
});